package ocean

import (
	"cid-media-api/api/common"
	"cid-media-api/models"
	"context"
	. "github.com/oceanengine/ad_open_sdk_go/models"
	"net/http"
)

func GetMaterialReport(account models.MediaAccount,
	startDate string,
	endDate string,
	page int32,
	pSize int32) *ReportCustomGetV30ResponseData {

	ctx := context.Background()
	dimensions := []string{
		"ad_platform_material_name",
		"ad_platform_material_content",
		"image_mode",
		"material_id",
		"cdp_project_id",
		"cdp_project_name",
		"cdp_promotion_id",
		"cdp_promotion_name",
		"stat_time_day",
	}
	metrics := []string{
		"stat_cost",
		"show_cnt",
		"cpm_platform",
		"click_cnt",
		"ctr",
		"cpc_platform",
		"convert_cnt",
		"conversion_cost",
		"conversion_rate",
		"deep_convert_cnt",
		"deep_convert_cost",
		"deep_convert_rate",
		"pay_amount_roi",
		"total_play",
		"valid_play",
		"in_app_order_gmv",
		"in_app_order_roi",
		"play_duration_3s",
		"play_25_feed_break",
		"play_50_feed_break",
		"play_75_feed_break",
		"play_99_feed_break",
	}

	filters := []*ReportCustomGetV30FiltersInner{{
		Field:    "image_mode",
		Operator: 0,
		Type:     1,
		Values:   []string{"2", "3", "5", "15", "16", "148", "157", "4", "154", "131"},
	}}

	orderBy := []*ReportCustomGetV30OrderByInner{{
		Field: "stat_cost",
		Type:  DESC_ReportCustomGetV30OrderByType.Ptr(),
	}}

	res, _ := Call(func() (any, *http.Response, error) {
		return Api.ReportCustomGetV30Api().Get(ctx).
			AccessToken(account.AccessToken).
			AdvertiserId(account.AdvertiserId).
			DataTopic(MATERIAL_DATA_ReportCustomGetV30DataTopic).
			Dimensions(dimensions).
			Metrics(metrics).
			Filters(filters).
			StartTime(startDate).
			EndTime(endDate).
			OrderBy(orderBy).
			Page(page).
			PageSize(pSize).
			Execute()

	}, common.GetCustomReport())

	if res == nil {
		return nil
	}

	resData := res.(*ReportCustomGetV30Response).Data

	return resData
}
